package com.mh.www.mh_frame.presenter.present.impl;

import com.mh.www.mh_frame.model.bean.FileUtils;
import com.mh.www.mh_frame.model.bean.HttpCallBack;
import com.mh.www.mh_frame.model.bean.L;
import com.mh.www.mh_frame.model.bean.MeetingSummaryBean;
import com.mh.www.mh_frame.network.RetrofitFactory;
import com.mh.www.mh_frame.presenter.iview.MeetingSummaryView;
import com.mh.www.mh_frame.presenter.present.MeetingSummaryPresent;
import com.mh.www.mh_frame.presenter.present.base.BasePresenterImpl;
import com.mh.www.mh_frame.view.activity.MeetingSummaryActivity;
import com.orhanobut.logger.Logger;

import java.io.File;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by lenovo on 2018/4/19.
 */

public class MeetingSummaryPresentImpl extends BasePresenterImpl<MeetingSummaryView> implements MeetingSummaryPresent {
    @Override
    public void getSummary(String titles, String pagenum, String types, String pipeLineId) {
        RetrofitFactory.getInstence().API()
                .getMeetingSummary(titles,pagenum,types,pipeLineId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<MeetingSummaryBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(MeetingSummaryBean meetingSummaryBean) {
                        Logger.e("onNext"+"---"+meetingSummaryBean);
                            mView.setData(meetingSummaryBean);
                    }

                    @Override
                    public void onError(Throwable e) {
                        Logger.e("onError"+e.getMessage()+"--");
                    }
                    @Override
                    public void onComplete() {
                        Logger.e("完成","onCompleted");
                    }
                });
    }

    @Override
    public void getLoadPDF(String fileName) {
        RetrofitFactory.getInstence().API()
                .downloadFile("uploadfile/"+fileName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResponseBody>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResponseBody responseBody) {
                        mView.setPDF(responseBody);
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
